package com.qys.training.biz.alive.listener;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.ITopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author Winstone
 * @date 2020/8/5 - 5:51 下午
 */
@Component
public class ServiceRegistListener implements ApplicationListener<ApplicationStartedEvent> {

    @Autowired
    HazelcastInstance client;

    public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
        AliveListener aliveListener = new AliveListener(client);
        ITopic topic = client.getTopic("alive");
        topic.addMessageListener(aliveListener);

        new Thread(new OfflineListener(client)).start();
    }
}
